package cn.drew.house.service.impl;

import cn.drew.basic.utils.PageList;
import cn.drew.house.domain.RentingInformation;
import cn.drew.house.mapper.RentingInformationMapper;
import cn.drew.house.query.RentingInformationQuery;
import cn.drew.house.service.RentingInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class RentingInformationServiceImpl implements RentingInformationService {

    @Autowired
    private RentingInformationMapper rentingInformationMapper;
    @Override
    public void add(RentingInformation rentingInformation) {
        rentingInformationMapper.add(rentingInformation);
    }

    @Override
    public void update(RentingInformation rentingInformation) {
        rentingInformationMapper.update(rentingInformation);
    }

    @Override
    public void delete(Long id) {
        rentingInformationMapper.delete(id);
    }

    @Override
    public RentingInformation findById(Long id) {
        return rentingInformationMapper.findById(id);
    }

    @Override
    public List<RentingInformation> findAll() {
        return rentingInformationMapper.findAll();
    }



    @Override
    public PageList<RentingInformation> queryByPage(RentingInformationQuery rentingInformationQuery) {
        Integer count = rentingInformationMapper.queryByCount(rentingInformationQuery);
        if (count == 0 || count == null){
            return new PageList(0,new ArrayList());
        }else{
            List<RentingInformation> rentingInformations = rentingInformationMapper.queryByPage(rentingInformationQuery);
            return new PageList<RentingInformation>(count,rentingInformations);
        }

    }

    @Override
    public void patchDelete(List<Long> ids) {
        rentingInformationMapper.patchDelete(ids);
    }

//    @Override
//    public List<RentingInformation> findByDeptid(Long deptid) {
//        List<RentingInformation> RentingInformations = rentingInformationMapper.findAll();
//        System.out.println(deptid);
//        //将departmentId 和deptid 相等的数据过滤 ,再转化为list
//        return RentingInformations.stream().filter(emp -> deptid.equals(emp.getDepartmentId())).collect(Collectors.toList());
//
//    }
}
